package com.fyzk.activity.special;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.fyzk.bean.CoinDetailBean;
import com.tyjc.lottery.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by fanxs11 on 16/12/28.
 */

public class CoinDetailAdapter extends BaseAdapter {

    private Context context;
    private List<CoinDetailBean.ValueBean.DataBean> infos = new ArrayList<>();

    public CoinDetailAdapter(Context context, List<CoinDetailBean.ValueBean.DataBean> infos) {
        this.context = context;
        this.infos = infos;
    }

    @Override
    public int getCount() {
        if (infos != null) {
            return infos.size();
        } else {
            return 0;
        }
    }

    @Override
    public Object getItem(int position) {
        if (infos.size() > 0) {
            return infos.get(position);
        }
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        CoinDetailBean.ValueBean.DataBean bean = infos.get(position);

        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.adapter_coin_detail, null);
            holder.img = (ImageView) convertView.findViewById(R.id.coin_detail_item_img);
            holder.name = (TextView) convertView.findViewById(R.id.coin_detail_item_name);
            holder.coin = (TextView) convertView.findViewById(R.id.coin_detail_item_coin);
            holder.time = (TextView) convertView.findViewById(R.id.coin_detail_item_time);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        String jiaOrJian = "+";
        // chongzhi|yonghuxinxi|goucai|qiandao
        if (bean.getType().equals("chongzhi")) {
            holder.img.setImageDrawable(context.getResources().getDrawable(R.drawable.coin_detail_choujiang));
            jiaOrJian = "-";
        } else if (bean.getType().equals("goucai")) {
            holder.img.setImageDrawable(context.getResources().getDrawable(R.drawable.coin_detail_goucai));
        } else if (bean.getType().equals("qiandao")) {
            holder.img.setImageDrawable(context.getResources().getDrawable(R.drawable.coin_detail_qiandao));
        } else {
            holder.img.setImageDrawable(context.getResources().getDrawable(R.drawable.coin_detail_zhongjiang));
        }
        holder.name.setText(bean.getType());
        holder.coin.setText(jiaOrJian+bean.getAmount());

        holder.time.setText(bean.getRecord_time());


        return convertView;
    }

    public void setInfos(List<CoinDetailBean.ValueBean.DataBean> infos) {
        this.infos = infos;
        this.notifyDataSetChanged();
    }

    class ViewHolder {
        ImageView img;
        TextView name;
        TextView coin;
        TextView time;
    }
}
